/*******************************************************************************
 * Package: com.hngtrust.framework.util
 * Type:    MD5Util
 * Date:    2020/11/23 19:16
 *
 * Copyright (c) 2020 HUANENG GUICHENG TRUST CORP.,LTD All Rights Reserved.
 *
 * You may not use this file except in compliance with the License.
 *******************************************************************************/
package com.hngtrust.iir.third.util;

import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;

/**
 * TODO your comment
 *
 * @author Qiaohesong
 * @date 2020/11/23 19:16
 */
@Slf4j
public class MD5Util {
    public static String  mD5Bit32 (String text) {
        StringBuffer sb = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes("UTF-8"));
            byte[] b = md.digest();
            int i;
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    sb.append("0");
                }
                sb.append(Integer.toHexString(i));
            }
        } catch (Exception e) {
            log.error("md5加密失败");
            return null;
        }
        return sb.toString().toUpperCase();
    }
}
